test: regression test for initialize hang on unexpected content-type#2472
test: regression test for initialize hang on unexpected content-type#2472Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
…ype (modelcontextprotocol#2432) Add a test that verifies initialize() raises MCPError immediately when the server returns an unexpected Content-Type (e.g. text/plain) instead of hanging forever waiting for a response that never arrives. Fixes modelcontextprotocol#2432
|
Friendly bump -- let me know if anything needs changing. |
1 similar comment
|
Friendly bump -- let me know if anything needs changing. |
|
Does the same fix path also cover a server returning 200 with an empty body, or 200 with valid JSON for a different request id? Both have the same "initialize never resolves" shape, so if the fix is at the right layer they should unblock without new code. If those cases are tested elsewhere already, ignore. |
|
No — this test is scoped to the unexpected content-type path only. The hang in issue #2432 is triggered when the SDK reaches the The two cases you describe follow different paths:
Both are valid "initialize never resolves" failure modes but would need separate tests against the relevant code paths. Happy to add them here or in a follow-up PR if that's useful. |
Summary
test_initialize_does_not_hang_on_unexpected_content_type) that directly reproduces the hang described in issue Initialize call hangs forever if MCP server does not return aContent-Type: text/plain#2432Content-Type: text/plainfor all requests (includinginitialize) and asserts thatsession.initialize()raisesMCPErrorimmediately instead of blocking foreverThe underlying fix is already present on
main—_handle_post_requestsends a properJSONRPCError(with the matching request ID) when it encounters an unexpected content type, which letsClientSessionresolve the pending request instead of waiting indefinitely. This PR adds the missing test that exercises that code path for theinitializecall specifically.Test plan
tests/client/test_notification_response.py::test_initialize_does_not_hang_on_unexpected_content_type— new test passestest_notification_response.pytests continue to passFixes #2432